<?php
/**
 * Created by PhpStorm.
 * Admininfo: Administrator
 * Date: 2018/3/21
 * Time: 16:09
 */
namespace app\admin\controller;
use app\common\controller\Curt;
use think\Db;
class  Discount extends Curt {
    function __construct()
    {
        parent::__construct($upload = true,$uploadConfig = array(
            'input_name' => 'coverFile',//文本框name
            'data_field' => 'cover'//数据库字段
        ));
    }
    public function getall()
    {
        $keyword=trim(input('get.keyword'));
        if($keyword){
            $where['name']=['like','%'.$keyword.'%'];//优惠券名称查询
        }
        if(input('get.begin') && input('get.end')){
            $where['starttime'] =['between',[strtotime(input('get.begin').' '.'00:00:00'),strtotime(input('get.end').' '.'23:59:59')]];
        }
        if(input('get.begin') && !input('get.end')){
            $where['starttime']=['>=',strtotime(input('get.begin').' '.'00:00:00')];
        }
        if(input('get.end') && !input('get.begin')){
            $where['starttime']=['<=',strtotime(input('get.end').' '.'23:59:59')];
        }
        if(input('get.begins') && input('get.ends')){
            $where['endtime'] =['between',[strtotime(input('get.begin').' '.'00:00:00'),strtotime(input('get.end').' '.'23:59:59')]];
        }
        if(input('get.begins') && !input('get.ends')){
            $where['endtime']=['>=',strtotime(input('get.begin').' '.'00:00:00')];
        }
        if(input('get.ends') && !input('get.begins')){
            $where['endtime']=['<=',strtotime(input('get.end').' '.'23:59:59')];
        }
        $list = $this->model->where($where)->order('id desc')->paginate();
        $page = $list->render();
        $this->assign('list', $list);
        $this->assign('begin', input('get.begin'));
        $this->assign('end', input('get.end'));
        $this->assign('begins', input('get.begins'));
        $this->assign('ends', input('get.ends'));
        $this->assign('page', $page);
    }

    /*添加*/
   public function add_(){
        if($this->request->isPost()){
            $data=$this->request->param();
            $data['sup_num']=input("num");
            $data['starttime']=strtotime(input("starttime"));
            $data['endtime']=strtotime(input("endtime"));
            $addInfo=Db::name('discount')->insert($data);
            $this->addend($addInfo);
        }else{
            $this->fetch();
        }
    }

}

